"""
 -*- coding: utf-8-*-
 @File: page_home.py
 @Author: chen
 @time: 2024/01/09/ 21:51
"""
import os.path
import time

from ui_test.page_po_test.page_business.page_base import BasePage
from ui_test.page_po_test.page_utils.mgt_yaml import YamlMgt

cur_path = os.path.dirname(os.path.abspath(__file__))
config_file = os.path.join(cur_path, r"config/pet_ui_config.yaml")
config_data = YamlMgt.read(config_file)


class HomePage(BasePage):
    """首页"""
    _test_url = config_data.get("test_url")

    def get_home(self):
        self.logger.info("打开测试网站")
        self.do_get(self._test_url)
        return self

    def click_owner_menu(self):
        btn_owners = (self.by.XPATH, '//*[text()="Owners"]')
        self.logger.info("点击owner菜单")
        self.do_click(btn_owners)
        return self

    def click_search_btn(self):
        btn_search = (self.by.XPATH, '//*[text()=" Search"]')
        self.logger.info("点击search按钮")
        self.do_click(btn_search)
        return self

    def click_add_new_btn(self):
        btn_add = (self.by.XPATH, '//*[text()=" Add New"]')
        self.logger.info(f"点击{btn_add}按钮")
        self.do_click(btn_add)
        return self

    def goto_create_owner_page(self):
        self.get_home().\
            click_owner_menu().\
            click_add_new_btn()
        from ui_test.page_po_test.page_business.page_create_owner import CreateOwnerPage
        self.logger.info("进入添加宠物主人页面")
        return CreateOwnerPage(self.driver)

    def goto_owner_mgt_page(self):
        self.get_home().\
            click_owner_menu().\
            click_search_btn()
        from ui_test.page_po_test.page_business.page_owner_mgt import OwnerMgtPage
        self.logger.info("进入宠物主人管理页面")
        return OwnerMgtPage(self.driver)


if __name__ == '__main__':
    cur_page = HomePage()
    cur_page.get_home().goto_create_owner_page()
    time.sleep(3)
